<!--
To change this template, choose Tools | Templates
and open the template in the editor.

if (!isset($_REQUEST['sessionId']) ||
            !isset($_REQUEST['comment']) || !isset($_REQUEST['content']) || 
            !isset($_REQUEST['latitude']) || !isset($_REQUEST['longitude'])) {
        throw new Exception('Parameters are missing', 403);
    } else {
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
<form action="terenacapi.php"
enctype="multipart/form-data" method="post">
    <p>
        SessionID: <br>
    <input type="text"  name="sessionId" size="30">
    </p>
    <p>
        Comment: <br>
    <input type="text"  name="comment" size="30">
    </p>
    <p>
        UserId: <br>
    <input type="text"  name="usernameID" size="30">
    </p>
    <p>
        Latitude: <br>
    <input type="text"  name="latitude" size="30">
    </p>
    <p>
        Longitude: <br>
    <input type="text"  name="longitude" size="30">
    </p>
     <p>
        action: <br>
    <input type="text"  name="action" size="30">
    </p>
    <p>
        Picture:<br>
    <input type="file" name="picture" size="40">
    </p>
    <div><input type="submit" value="Send"></div>
</form>

        <?php
        require 'database.inc.php';
        require 'Message.php';
        require 'MessageRepository.php';        
        
        $messageRepository = new MessageRepository();
        if (!empty($_POST) && !empty($_FILES['picture'])) {
            var_dump($_POST);
            var_dump($_FILES);
            $newFileName = array_pop(explode('/',tempnam('./pictures','')));
            var_dump($newFileName);
            if (!move_uploaded_file($_FILES['picture']['tmp_name'], './pictures/'.$newFileName)) {
                throw new Exception('File not safe', 403);
            }
            $message = new Message(0,$_POST['usernameID'],$_POST['comment'], 
                    $newFileName, $_FILES['picture']['type'],0,$_POST['latitude'],
                    $_POST['longitude']);
            var_dump($message);
            $messageRepository->addMessage($db, $message);
            
}           
        ?>
    </body>
</html>
